#ifndef SENSOR_CONFIG_H
#define SENSOR_CONFIG_H

#include "sensor_common.h"

#define TRANSMITER_TYPE    14



#define GLUCOSE_PER_HOUR            12
#define SAMPLES_PER_HOUR            12
#define BLANK_SECONDS_AFTER_EIS     30
#define LEVEL1_SAMPLE_SECONDS       60
#define LEVEL2_SAMPLE_SECONDS      ( SECONDS_PER_HOUR / GLUCOSE_PER_HOUR / 5 )

#define FIR_FILTER_COEF            { 85,85,85,85,85,15,15,15,15,15 }
// #define FIR_FILTER_COEF2           { 100,100,100,100,100,0,0,0,0,0 }
#define FIR_FILTER_LENGTH           10

#if SAMPLES_PER_HOUR <= 12
#define SAVIT_FILTER_LENGTH         5
#elif SAMPLES_PER_HOUR <= 24
#define SAVIT_FILTER_LENGTH         10
#else
#define SAVIT_FILTER_LENGTH         15
#endif

#define WR_BIAS                    ( 44 * PERCISION / 100 )

#define ISIG_UPPER                 (200 * PERCISION )
#define ISIG_LOWER                    0
#define ISIG_ROC_UPPER             ( 20 * PERCISION / 100 )

#define CAL_FACTOR_UPPER_THRESHOLD (  5 * PERCISION )
#define CAL_FACTOR_LOWER_THRESHOLD (  2 * PERCISION / 10 )
#define OFFSET_UPPER_THRESHOLD     (  1 * PERCISION / 10 )

#define FREQUENCY_COUNT               1

#define INIT_SECONDS               ( 60 * SECONDS_PER_MINUTE )

#define ENABLE_DIFF_DETECTION
//#define ENABLE_VCOUNTER_ADJUSTMENT
#define ENABLE_NONLINEAR_ADJUSTMENT
#define ENABLE_OVERSHOOT_CORRECTION
#define ENABLE_DROPOUT_CORRECTION
#define ENABLE_KALMAN_FILTER
#define ENABLE_IMP_ERROR_CHECK
#define ENABLE_IMP_AUTOCAL
//#define ENABLE_IMP_AUTOCAL_PROG
//#define ENABLE_GLUCOSE_PREDICT

//#define ENABLE_RAPID_CAL
//#define ENABLE_WEIGHTED_CAL
//#define ENABLE_GRADUAL_CAL
#define POST_CAL_TIMES      2

#ifdef ENABLE_RAPID_CAL
#undef ENABLE_WEIGHTED_CAL
#undef ENABLE_GRADUAL_CAL
#define POST_CAL_TIMES       0
#endif

#if POST_CAL_TIMES == 0
#undef ENABLE_GRADUAL_CAL
#endif

#define SENSOR_AUTOBASE        1

//sensor param version 1.0.6

#if TRANSMITER_TYPE == 14

#define DP_EXPIRATION_TIME              (  14 * SECONDS_PER_DAY )
#define DP_CAL_FACTOR_DEFAULT           (  0 * PERCISION / 100 )
#define DP_OFFSET_DEFAULT               (  50 * PERCISION / 100 )
#define DP_CAL_FACTOR_1                 ( 100 * PERCISION / 100 )
#define DP_CAL_FACTOR_2                 (  115 * PERCISION / 100 )
#define DP_CAL_FACTOR_3                 (  105 * PERCISION / 100 )
#define DP_CAL_FACTOR_4                 ( 105 * PERCISION / 100 )
#define DP_CAL_FACTOR_5                 ( 130 * PERCISION / 100 )
#define DP_CAL_FACTOR_HOURS2            (  6 * PERCISION       )
#define DP_CAL_FACTOR_HOURS3            ( 36 * PERCISION       )
#define DP_CAL_FACTOR_HOURS4            ( 192 * PERCISION       )
#define DP_OFFSET_1                     ( 80 * PERCISION / 100 )
#define DP_OFFSET_2                     (  80 * PERCISION / 100 )
#define DP_OFFSET_3                     (   0 * PERCISION / 100 )
#define DP_OFFSET_4                     (  0 * PERCISION / 100 )
#define DP_OFFSET_5                     ( 30 * PERCISION / 100 )
#define DP_OFFSET_HOURS2                (  24 * PERCISION       )
#define DP_OFFSET_HOURS3                ( 96 * PERCISION       )
#define DP_OFFSET_HOURS4                ( 240 * PERCISION       )
#define DP_INITIALIZAION_BIAS           (  44 * PERCISION / 100 )
#define DP_ISIG_REF_DEFAULT             (   25 * PERCISION/10 )
#define DP_ISIG_NONLINEAR_C1            (   12 * PERCISION / 10 )
#define DP_ISIG_NONLINEAR_C0            (   7 * PERCISION )
#define DP_CAL_FACTOR_LOWER_SCALE       (  40 * PERCISION / 100 )
#define DP_CAL_FACTOR_UPPER_SCALE       ( 250 * PERCISION / 100 )
#define DP_SENS_FACTOR_LOWER            (  50 * PERCISION / 100 )
#define DP_SENS_FACTOR_UPPER            ( 160 * PERCISION / 100 )
#define DP_REF_REAL_LOWER               (  30 * PERCISION )
#define DP_REF_REAL_UPPER               ( 150 * PERCISION )
#define DP_REF_REAL_NEW_SENSOR          (  70 * PERCISION )
#define DP_REF_REAL_DEFAULT             (  70 * PERCISION )
#define DP_REF_REAL_FACTOR              (   10 * PERCISION / 100 )
#define DP_REF_REAL_CHANGE_START_HOUR   (   0 * PERCISION )
#define DP_REF_REAL_CHANGE_PER_HOUR     (   0 * PERCISION / 100 )
#define DP_REF_REAL_SENS_CHANGED        ( 200 * PERCISION )
#define DP_REF_IMAG_LOWER               ( -20 * PERCISION )
#define DP_REF_IMAG_UPPER               (  20 * PERCISION )
#define DP_REF_IMAG_DEFAULT             (   1 * PERCISION )
#define DP_REF_IMAG_FACTOR              ( 5 * PERCISION / 100 )
#define DP_REF_IMAG_SENS_CHANGED        ( 100 * PERCISION )
#define DP_REF_IMAG_OFFSET              (  8 * PERCISION / 100 )

#elif TRANSMITER_TYPE == 10


#define DP_EXPIRATION_TIME              (  10 * SECONDS_PER_DAY )
#define DP_CAL_FACTOR_DEFAULT           (  0 * PERCISION / 100 )
#define DP_OFFSET_DEFAULT               (  50 * PERCISION / 100 )
#define DP_CAL_FACTOR_1                 ( 100 * PERCISION / 100 )
#define DP_CAL_FACTOR_2                 (  115 * PERCISION / 100 )
#define DP_CAL_FACTOR_3                 (  105 * PERCISION / 100 )
#define DP_CAL_FACTOR_4                 ( 105 * PERCISION / 100 )
#define DP_CAL_FACTOR_5                 ( 114 * PERCISION / 100 )
#define DP_CAL_FACTOR_HOURS2            (  6 * PERCISION       )
#define DP_CAL_FACTOR_HOURS3            ( 36 * PERCISION       )
#define DP_CAL_FACTOR_HOURS4            ( 192 * PERCISION       )
#define DP_OFFSET_1                     ( 80 * PERCISION / 100 )
#define DP_OFFSET_2                     (  80 * PERCISION / 100 )
#define DP_OFFSET_3                     (   0 * PERCISION / 100 )
#define DP_OFFSET_4                     (  0 * PERCISION / 100 )
#define DP_OFFSET_5                     (  0 * PERCISION / 100 )
#define DP_OFFSET_HOURS2                (  24 * PERCISION       )
#define DP_OFFSET_HOURS3                ( 96 * PERCISION       )
#define DP_OFFSET_HOURS4                ( 200 * PERCISION       )
#define DP_INITIALIZAION_BIAS           (  44 * PERCISION / 100 )
#define DP_ISIG_REF_DEFAULT             (   25 * PERCISION/ 10)
#define DP_ISIG_NONLINEAR_C1            (   12 * PERCISION / 10 )
#define DP_ISIG_NONLINEAR_C0            (   7 * PERCISION )
#define DP_CAL_FACTOR_LOWER_SCALE       (  40 * PERCISION / 100 )
#define DP_CAL_FACTOR_UPPER_SCALE       ( 250 * PERCISION / 100 )
#define DP_SENS_FACTOR_LOWER            (  50 * PERCISION / 100 )
#define DP_SENS_FACTOR_UPPER            ( 160 * PERCISION / 100 )
#define DP_REF_REAL_LOWER               (  30 * PERCISION )
#define DP_REF_REAL_UPPER               ( 150 * PERCISION )
#define DP_REF_REAL_NEW_SENSOR          (  70 * PERCISION )
#define DP_REF_REAL_DEFAULT             (  70 * PERCISION )
#define DP_REF_REAL_FACTOR              (   10 * PERCISION / 100 )
#define DP_REF_REAL_CHANGE_START_HOUR   (   0 * PERCISION )
#define DP_REF_REAL_CHANGE_PER_HOUR     (   0 * PERCISION / 100 )
#define DP_REF_REAL_SENS_CHANGED        ( 200 * PERCISION )
#define DP_REF_IMAG_LOWER               ( -20 * PERCISION )
#define DP_REF_IMAG_UPPER               (  20 * PERCISION )
#define DP_REF_IMAG_DEFAULT             (   1 * PERCISION )
#define DP_REF_IMAG_FACTOR              ( 5 * PERCISION / 100 )
#define DP_REF_IMAG_SENS_CHANGED        ( 100 * PERCISION )
#define DP_REF_IMAG_OFFSET              (  8 * PERCISION / 100 )


#elif TRANSMITER_TYPE == 7

#define DP_EXPIRATION_TIME              (   7 * SECONDS_PER_DAY )
#define DP_CAL_FACTOR_DEFAULT           (  0 * PERCISION / 100 )
#define DP_OFFSET_DEFAULT               (  50 * PERCISION / 100 )
#define DP_CAL_FACTOR_1                 ( 100 * PERCISION / 100 )
#define DP_CAL_FACTOR_2                 (  115 * PERCISION / 100 )
#define DP_CAL_FACTOR_3                 (  105 * PERCISION / 100 )
#define DP_CAL_FACTOR_4                 (  105 * PERCISION / 100 )
#define DP_CAL_FACTOR_5                 (  105 * PERCISION / 100 )
#define DP_CAL_FACTOR_HOURS2            (  6 * PERCISION       )
#define DP_CAL_FACTOR_HOURS3            ( 36 * PERCISION       )
#define DP_CAL_FACTOR_HOURS4            ( 160 * PERCISION       )
#define DP_OFFSET_1                     ( 80 * PERCISION / 100 )
#define DP_OFFSET_2                     (  80 * PERCISION / 100 )
#define DP_OFFSET_3                     (  0 * PERCISION / 100 )
#define DP_OFFSET_4                     (   0 * PERCISION / 100 )
#define DP_OFFSET_5                     (   0 * PERCISION / 100 )
#define DP_OFFSET_HOURS2                (  24 * PERCISION       )
#define DP_OFFSET_HOURS3                (  96 * PERCISION       )
#define DP_OFFSET_HOURS4                ( 160 * PERCISION       )
#define DP_INITIALIZAION_BIAS           (  44 * PERCISION / 100 )
#define DP_ISIG_REF_DEFAULT             (   25 * PERCISION /10)
#define DP_ISIG_NONLINEAR_C1            (   12 * PERCISION / 10 )
#define DP_ISIG_NONLINEAR_C0            (   7 * PERCISION )
#define DP_CAL_FACTOR_LOWER_SCALE       (  40 * PERCISION / 100 )
#define DP_CAL_FACTOR_UPPER_SCALE       ( 250 * PERCISION / 100 )
#define DP_SENS_FACTOR_LOWER            (  50 * PERCISION / 100 )
#define DP_SENS_FACTOR_UPPER            ( 160 * PERCISION / 100 )
#define DP_REF_REAL_LOWER               (  30 * PERCISION )
#define DP_REF_REAL_UPPER               ( 150 * PERCISION )
#define DP_REF_REAL_NEW_SENSOR          (  70 * PERCISION )
#define DP_REF_REAL_DEFAULT             (  70 * PERCISION )
#define DP_REF_REAL_FACTOR              (   10 * PERCISION / 100 )
#define DP_REF_REAL_CHANGE_START_HOUR   (   0 * PERCISION )
#define DP_REF_REAL_CHANGE_PER_HOUR     (   0 * PERCISION / 100 )
#define DP_REF_REAL_SENS_CHANGED        ( 200 * PERCISION )
#define DP_REF_IMAG_LOWER               ( -20 * PERCISION )
#define DP_REF_IMAG_UPPER               (  20 * PERCISION )
#define DP_REF_IMAG_DEFAULT             (   1 * PERCISION )
#define DP_REF_IMAG_FACTOR              ( 5 * PERCISION / 100 )
#define DP_REF_IMAG_SENS_CHANGED        ( 100 * PERCISION )
#define DP_REF_IMAG_OFFSET              (  8 * PERCISION / 100 )

#endif
typedef struct
{
    uint32 EXPIRATION_TIME;
    uint16 CAL_FACTOR_DEFAULT;
    sint16 OFFSET_DEFAULT;
    uint16 CAL_FACTOR_1;
    uint16 CAL_FACTOR_2;
    uint16 CAL_FACTOR_3;
    uint16 CAL_FACTOR_4;
    uint16 CAL_FACTOR_5;
    uint16 CAL_FACTOR_HOURS2;
    uint16 CAL_FACTOR_HOURS3;
    uint16 CAL_FACTOR_HOURS4;
    sint16 OFFSET_1;
    sint16 OFFSET_2;
    sint16 OFFSET_3;
    sint16 OFFSET_4;
    sint16 OFFSET_5;
    uint16 OFFSET_HOURS2;
    uint16 OFFSET_HOURS3;
    uint16 OFFSET_HOURS4;
    uint16 INITIALIZAION_BIAS;
    sint16 ISIG_REF_DEFAULT;
    sint16 ISIG_NONLINEAR_C1;
    sint16 ISIG_NONLINEAR_C0;
    uint16 CAL_FACTOR_LOWER_SCALE;
    uint16 CAL_FACTOR_UPPER_SCALE;
    uint16 SENS_FACTOR_LOWER;
    uint16 SENS_FACTOR_UPPER;
    sint16 REF_REAL_LOWER;
    sint16 REF_REAL_UPPER;
    sint16 REF_REAL_NEW_SENSOR;
    sint16 REF_REAL_DEFAULT;
    sint16 REF_REAL_FACTOR;
    uint16 REF_REAL_CHANGE_START_HOUR;
    sint16 REF_REAL_CHANGE_PER_HOUR;
    sint16 REF_REAL_SENS_CHANGED;
    sint16 REF_IMAG_LOWER;
    sint16 REF_IMAG_UPPER;
    sint16 REF_IMAG_DEFAULT;
    sint16 REF_IMAG_FACTOR;
    sint16 REF_IMAG_SENS_CHANGED;
    sint16 REF_IMAG_OFFSET;
} sensor_default_param;
extern sensor_default_param DP;

#endif // SENSOR_CONFIG_H
